<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>numbermatcher.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_labs_testing_numbermatcher.js.html">numbermatcher.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Provides the built-in number matchers like lessThan,
<a name="line17"></a> * greaterThan, etc.
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.labs.testing.CloseToMatcher&#39;);
<a name="line22"></a>goog.provide(&#39;goog.labs.testing.EqualToMatcher&#39;);
<a name="line23"></a>goog.provide(&#39;goog.labs.testing.GreaterThanEqualToMatcher&#39;);
<a name="line24"></a>goog.provide(&#39;goog.labs.testing.GreaterThanMatcher&#39;);
<a name="line25"></a>goog.provide(&#39;goog.labs.testing.LessThanEqualToMatcher&#39;);
<a name="line26"></a>goog.provide(&#39;goog.labs.testing.LessThanMatcher&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line30"></a>goog.require(&#39;goog.labs.testing.Matcher&#39;);
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>/**
<a name="line35"></a> * The GreaterThan matcher.
<a name="line36"></a> *
<a name="line37"></a> * @param {number} value The value to compare.
<a name="line38"></a> *
<a name="line39"></a> * @constructor
<a name="line40"></a> * @struct
<a name="line41"></a> * @implements {goog.labs.testing.Matcher}
<a name="line42"></a> * @final
<a name="line43"></a> */
<a name="line44"></a>goog.labs.testing.GreaterThanMatcher = function(value) {
<a name="line45"></a>  /**
<a name="line46"></a>   * @type {number}
<a name="line47"></a>   * @private
<a name="line48"></a>   */
<a name="line49"></a>  this.value_ = value;
<a name="line50"></a>};
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>/**
<a name="line54"></a> * Determines if input value is greater than the expected value.
<a name="line55"></a> *
<a name="line56"></a> * @override
<a name="line57"></a> */
<a name="line58"></a>goog.labs.testing.GreaterThanMatcher.prototype.matches = function(actualValue) {
<a name="line59"></a>  goog.asserts.assertNumber(actualValue);
<a name="line60"></a>  return actualValue &gt; this.value_;
<a name="line61"></a>};
<a name="line62"></a>
<a name="line63"></a>
<a name="line64"></a>/**
<a name="line65"></a> * @override
<a name="line66"></a> */
<a name="line67"></a>goog.labs.testing.GreaterThanMatcher.prototype.describe =
<a name="line68"></a>    function(actualValue) {
<a name="line69"></a>  goog.asserts.assertNumber(actualValue);
<a name="line70"></a>  return actualValue + &#39; is not greater than &#39; + this.value_;
<a name="line71"></a>};
<a name="line72"></a>
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * The lessThan matcher.
<a name="line77"></a> *
<a name="line78"></a> * @param {number} value The value to compare.
<a name="line79"></a> *
<a name="line80"></a> * @constructor
<a name="line81"></a> * @struct
<a name="line82"></a> * @implements {goog.labs.testing.Matcher}
<a name="line83"></a> * @final
<a name="line84"></a> */
<a name="line85"></a>goog.labs.testing.LessThanMatcher = function(value) {
<a name="line86"></a>  /**
<a name="line87"></a>   * @type {number}
<a name="line88"></a>   * @private
<a name="line89"></a>   */
<a name="line90"></a>  this.value_ = value;
<a name="line91"></a>};
<a name="line92"></a>
<a name="line93"></a>
<a name="line94"></a>/**
<a name="line95"></a> * Determines if the input value is less than the expected value.
<a name="line96"></a> *
<a name="line97"></a> * @override
<a name="line98"></a> */
<a name="line99"></a>goog.labs.testing.LessThanMatcher.prototype.matches = function(actualValue) {
<a name="line100"></a>  goog.asserts.assertNumber(actualValue);
<a name="line101"></a>  return actualValue &lt; this.value_;
<a name="line102"></a>};
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>/**
<a name="line106"></a> * @override
<a name="line107"></a> */
<a name="line108"></a>goog.labs.testing.LessThanMatcher.prototype.describe =
<a name="line109"></a>    function(actualValue) {
<a name="line110"></a>  goog.asserts.assertNumber(actualValue);
<a name="line111"></a>  return actualValue + &#39; is not less than &#39; + this.value_;
<a name="line112"></a>};
<a name="line113"></a>
<a name="line114"></a>
<a name="line115"></a>
<a name="line116"></a>/**
<a name="line117"></a> * The GreaterThanEqualTo matcher.
<a name="line118"></a> *
<a name="line119"></a> * @param {number} value The value to compare.
<a name="line120"></a> *
<a name="line121"></a> * @constructor
<a name="line122"></a> * @struct
<a name="line123"></a> * @implements {goog.labs.testing.Matcher}
<a name="line124"></a> * @final
<a name="line125"></a> */
<a name="line126"></a>goog.labs.testing.GreaterThanEqualToMatcher = function(value) {
<a name="line127"></a>  /**
<a name="line128"></a>   * @type {number}
<a name="line129"></a>   * @private
<a name="line130"></a>   */
<a name="line131"></a>  this.value_ = value;
<a name="line132"></a>};
<a name="line133"></a>
<a name="line134"></a>
<a name="line135"></a>/**
<a name="line136"></a> * Determines if the input value is greater than equal to the expected value.
<a name="line137"></a> *
<a name="line138"></a> * @override
<a name="line139"></a> */
<a name="line140"></a>goog.labs.testing.GreaterThanEqualToMatcher.prototype.matches =
<a name="line141"></a>    function(actualValue) {
<a name="line142"></a>  goog.asserts.assertNumber(actualValue);
<a name="line143"></a>  return actualValue &gt;= this.value_;
<a name="line144"></a>};
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>/**
<a name="line148"></a> * @override
<a name="line149"></a> */
<a name="line150"></a>goog.labs.testing.GreaterThanEqualToMatcher.prototype.describe =
<a name="line151"></a>    function(actualValue) {
<a name="line152"></a>  goog.asserts.assertNumber(actualValue);
<a name="line153"></a>  return actualValue + &#39; is not greater than equal to &#39; + this.value_;
<a name="line154"></a>};
<a name="line155"></a>
<a name="line156"></a>
<a name="line157"></a>
<a name="line158"></a>/**
<a name="line159"></a> * The LessThanEqualTo matcher.
<a name="line160"></a> *
<a name="line161"></a> * @param {number} value The value to compare.
<a name="line162"></a> *
<a name="line163"></a> * @constructor
<a name="line164"></a> * @struct
<a name="line165"></a> * @implements {goog.labs.testing.Matcher}
<a name="line166"></a> * @final
<a name="line167"></a> */
<a name="line168"></a>goog.labs.testing.LessThanEqualToMatcher = function(value) {
<a name="line169"></a>  /**
<a name="line170"></a>   * @type {number}
<a name="line171"></a>   * @private
<a name="line172"></a>   */
<a name="line173"></a>  this.value_ = value;
<a name="line174"></a>};
<a name="line175"></a>
<a name="line176"></a>
<a name="line177"></a>/**
<a name="line178"></a> * Determines if the input value is less than or equal to the expected value.
<a name="line179"></a> *
<a name="line180"></a> * @override
<a name="line181"></a> */
<a name="line182"></a>goog.labs.testing.LessThanEqualToMatcher.prototype.matches =
<a name="line183"></a>    function(actualValue) {
<a name="line184"></a>  goog.asserts.assertNumber(actualValue);
<a name="line185"></a>  return actualValue &lt;= this.value_;
<a name="line186"></a>};
<a name="line187"></a>
<a name="line188"></a>
<a name="line189"></a>/**
<a name="line190"></a> * @override
<a name="line191"></a> */
<a name="line192"></a>goog.labs.testing.LessThanEqualToMatcher.prototype.describe =
<a name="line193"></a>    function(actualValue) {
<a name="line194"></a>  goog.asserts.assertNumber(actualValue);
<a name="line195"></a>  return actualValue + &#39; is not less than equal to &#39; + this.value_;
<a name="line196"></a>};
<a name="line197"></a>
<a name="line198"></a>
<a name="line199"></a>
<a name="line200"></a>/**
<a name="line201"></a> * The EqualTo matcher.
<a name="line202"></a> *
<a name="line203"></a> * @param {number} value The value to compare.
<a name="line204"></a> *
<a name="line205"></a> * @constructor
<a name="line206"></a> * @struct
<a name="line207"></a> * @implements {goog.labs.testing.Matcher}
<a name="line208"></a> * @final
<a name="line209"></a> */
<a name="line210"></a>goog.labs.testing.EqualToMatcher = function(value) {
<a name="line211"></a>  /**
<a name="line212"></a>   * @type {number}
<a name="line213"></a>   * @private
<a name="line214"></a>   */
<a name="line215"></a>  this.value_ = value;
<a name="line216"></a>};
<a name="line217"></a>
<a name="line218"></a>
<a name="line219"></a>/**
<a name="line220"></a> * Determines if the input value is equal to the expected value.
<a name="line221"></a> *
<a name="line222"></a> * @override
<a name="line223"></a> */
<a name="line224"></a>goog.labs.testing.EqualToMatcher.prototype.matches = function(actualValue) {
<a name="line225"></a>  goog.asserts.assertNumber(actualValue);
<a name="line226"></a>  return actualValue === this.value_;
<a name="line227"></a>};
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>/**
<a name="line231"></a> * @override
<a name="line232"></a> */
<a name="line233"></a>goog.labs.testing.EqualToMatcher.prototype.describe =
<a name="line234"></a>    function(actualValue) {
<a name="line235"></a>  goog.asserts.assertNumber(actualValue);
<a name="line236"></a>  return actualValue + &#39; is not equal to &#39; + this.value_;
<a name="line237"></a>};
<a name="line238"></a>
<a name="line239"></a>
<a name="line240"></a>
<a name="line241"></a>/**
<a name="line242"></a> * The CloseTo matcher.
<a name="line243"></a> *
<a name="line244"></a> * @param {number} value The value to compare.
<a name="line245"></a> * @param {number} range The range to check within.
<a name="line246"></a> *
<a name="line247"></a> * @constructor
<a name="line248"></a> * @struct
<a name="line249"></a> * @implements {goog.labs.testing.Matcher}
<a name="line250"></a> * @final
<a name="line251"></a> */
<a name="line252"></a>goog.labs.testing.CloseToMatcher = function(value, range) {
<a name="line253"></a>  /**
<a name="line254"></a>   * @type {number}
<a name="line255"></a>   * @private
<a name="line256"></a>   */
<a name="line257"></a>  this.value_ = value;
<a name="line258"></a>  /**
<a name="line259"></a>   * @type {number}
<a name="line260"></a>   * @private
<a name="line261"></a>   */
<a name="line262"></a>  this.range_ = range;
<a name="line263"></a>};
<a name="line264"></a>
<a name="line265"></a>
<a name="line266"></a>/**
<a name="line267"></a> * Determines if input value is within a certain range of the expected value.
<a name="line268"></a> *
<a name="line269"></a> * @override
<a name="line270"></a> */
<a name="line271"></a>goog.labs.testing.CloseToMatcher.prototype.matches = function(actualValue) {
<a name="line272"></a>  goog.asserts.assertNumber(actualValue);
<a name="line273"></a>  return Math.abs(this.value_ - actualValue) &lt; this.range_;
<a name="line274"></a>};
<a name="line275"></a>
<a name="line276"></a>
<a name="line277"></a>/**
<a name="line278"></a> * @override
<a name="line279"></a> */
<a name="line280"></a>goog.labs.testing.CloseToMatcher.prototype.describe =
<a name="line281"></a>    function(actualValue) {
<a name="line282"></a>  goog.asserts.assertNumber(actualValue);
<a name="line283"></a>  return actualValue + &#39; is not close to(&#39; + this.range_ + &#39;) &#39; + this.value_;
<a name="line284"></a>};
<a name="line285"></a>
<a name="line286"></a>
<a name="line287"></a>/**
<a name="line288"></a> * @param {number} value The expected value.
<a name="line289"></a> *
<a name="line290"></a> * @return {!goog.labs.testing.GreaterThanMatcher} A GreaterThanMatcher.
<a name="line291"></a> */
<a name="line292"></a>function greaterThan(value) {
<a name="line293"></a>  return new goog.labs.testing.GreaterThanMatcher(value);
<a name="line294"></a>}
<a name="line295"></a>
<a name="line296"></a>
<a name="line297"></a>/**
<a name="line298"></a> * @param {number} value The expected value.
<a name="line299"></a> *
<a name="line300"></a> * @return {!goog.labs.testing.GreaterThanEqualToMatcher} A
<a name="line301"></a> *     GreaterThanEqualToMatcher.
<a name="line302"></a> */
<a name="line303"></a>function greaterThanEqualTo(value) {
<a name="line304"></a>  return new goog.labs.testing.GreaterThanEqualToMatcher(value);
<a name="line305"></a>}
<a name="line306"></a>
<a name="line307"></a>
<a name="line308"></a>/**
<a name="line309"></a> * @param {number} value The expected value.
<a name="line310"></a> *
<a name="line311"></a> * @return {!goog.labs.testing.LessThanMatcher} A LessThanMatcher.
<a name="line312"></a> */
<a name="line313"></a>function lessThan(value) {
<a name="line314"></a>  return new goog.labs.testing.LessThanMatcher(value);
<a name="line315"></a>}
<a name="line316"></a>
<a name="line317"></a>
<a name="line318"></a>/**
<a name="line319"></a> * @param {number} value The expected value.
<a name="line320"></a> *
<a name="line321"></a> * @return {!goog.labs.testing.LessThanEqualToMatcher} A LessThanEqualToMatcher.
<a name="line322"></a> */
<a name="line323"></a>function lessThanEqualTo(value) {
<a name="line324"></a>  return new goog.labs.testing.LessThanEqualToMatcher(value);
<a name="line325"></a>}
<a name="line326"></a>
<a name="line327"></a>
<a name="line328"></a>/**
<a name="line329"></a> * @param {number} value The expected value.
<a name="line330"></a> *
<a name="line331"></a> * @return {!goog.labs.testing.EqualToMatcher} An EqualToMatcher.
<a name="line332"></a> */
<a name="line333"></a>function equalTo(value) {
<a name="line334"></a>  return new goog.labs.testing.EqualToMatcher(value);
<a name="line335"></a>}
<a name="line336"></a>
<a name="line337"></a>
<a name="line338"></a>/**
<a name="line339"></a> * @param {number} value The expected value.
<a name="line340"></a> * @param {number} range The maximum allowed difference from the expected value.
<a name="line341"></a> *
<a name="line342"></a> * @return {!goog.labs.testing.CloseToMatcher} A CloseToMatcher.
<a name="line343"></a> */
<a name="line344"></a>function closeTo(value, range) {
<a name="line345"></a>  return new goog.labs.testing.CloseToMatcher(value, range);
<a name="line346"></a>}
</pre>


</body>
</html>
